package com.yuyou.tas.admin.test.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

@RunWith(SpringRunner.class)
@SpringBootTest
public class OfficeTokenControllerTest1 {
	
    MockMvc mvc;  
    
    @Autowired  
    WebApplicationContext webApplicationConnect; 
	// 在测试开始前初始化工作    
    @Before  
    public void setUp() throws JsonProcessingException {  
        mvc = MockMvcBuilders.webAppContextSetup(webApplicationConnect).build();  
  
    }
	
	@Test
	public void contextLoads() {
	}

	
    @Test
    public void upload() throws Exception {
        RequestBuilder request = MockMvcRequestBuilders.post("/api/token/upload")
                .param("accessToken","veftx0l1suzhwunnykzpvwtgbejdra")
                .param("resourceId","d27b0e2364e14bdeae34a944a035022c");
        MvcResult mvcResult = mvc.perform(request).andReturn();
        int status = mvcResult.getResponse().getStatus();
        String content = mvcResult.getResponse().getContentAsString();
        System.out.println(status);
        System.out.println(content);
    }
	
    @Test
    public void viewToken() throws Exception {
        RequestBuilder request = MockMvcRequestBuilders.post("/api/token/view")
                .param("accessToken","veftx0zmeu9ry3hseefwcffpwld6ug")
                .param("resourceId","d8d2754a702f4d31878d0dc170909082");
        MvcResult mvcResult = mvc.perform(request).andReturn();
        int status = mvcResult.getResponse().getStatus();
        String content = mvcResult.getResponse().getContentAsString();
        System.out.println(status);
        System.out.println(content);
    }

    @Test
    public void printToken() throws Exception {
        RequestBuilder request = MockMvcRequestBuilders.post("/api/token/print")
                .param("accessToken","veftx1v2zklmwkjltlhss0norkhxsa")
                .param("resourceId","4111683258e44120835d264de3279c57");
        MvcResult mvcResult = mvc.perform(request).andReturn();
        int status = mvcResult.getResponse().getStatus();
        String content = mvcResult.getResponse().getContentAsString();
        System.out.println(status);
        System.out.println(content);
    }

    
    @Test
    public void editToken() throws Exception {
        RequestBuilder request = MockMvcRequestBuilders.post("/api/token/edit")
                .param("accessToken","veftx2fqzwtrvw50zllpcktjrvd1sw")
                .param("resourceId","581f1219454541808fcc82749b06f582");
        MvcResult mvcResult = mvc.perform(request).andReturn();
        int status = mvcResult.getResponse().getStatus();
        String content = mvcResult.getResponse().getContentAsString();
        System.out.println(status);
        System.out.println(content);
    }
 
    
    
    
    
    
  
}
